#include "mystring.h"
#include <ostream>

void testString()
{

    real::string st = "hello world";
    st += " hheello!";
    cout << st << endl;

    st.reserve(5);
    cout << st.capacity() << endl;
    st.reserve(150);
    cout << st.capacity() << endl;
}

void testString2()
{

    real::string st = "hello world";
    st += " hheello!";
    cout << st << endl;

    real::string st2;
    st2 = st ;
    cout << st2 << endl;

    st2.clear();
    cout << st2 << endl;
    cout << st2.size() << endl;
    cout << st2.capacity() << endl;
}

void testString3()
{

    real::string st = "hello world";

    real::string st2 = st + "operator plus";
    cout << st2 << endl;
}

void testString4()
{
    real::string st = "abc";

    // const 不可以修改内容
    real::string::const_iterator begin = st.begin();
    while(begin != st.end())
    {
        printf("%c", *(begin++));
    }
    cout << endl << "=======================" << endl;

    // for(auto& ch: st) // 引用是指针本身
    for(auto ch: st) // 字符本身
    {
        cout << ch << " ";
    }
    cout << endl;
    cout << endl << "=======================" << endl;

    // 可以修改内容
    real::string::iterator begin2 = st.begin();
    while(begin2 != st.end())
    {
        (*begin2)++;
        printf("%c", *(begin2++));
    }
    cout << endl << "=======================" << endl;

}

void testString5()
{
    real::string st1 = "abc";
    real::string st2 = "b";

    cout << (st1<st2) << endl;
    cout << (st1>st2) << endl;
    cout << (st1=="abc") << endl;
    cout << (st1<="abc") << endl;
}

void testString6()
{
    real::string st1 = "abc";
    st1.push_back('e');
    cout << st1 << endl;
    st1.append("hoieu");
    cout << st1 << endl;
}

void testString7()
{
    real::string st = "Hello World";
    st.insert(0, '1');
    cout << st << endl;
    st.insert(st.size(), '*');
    cout << st << endl;
    st.insert(6, '$');
    cout << st << endl;

    real::string st2 = "Hello World";
    st2.insert(0, "abc_");
    cout << st2 << endl;
    st2.insert(st2.size(), "_cba");
    cout << st2 << endl;

    real::string st3 = "Hello World";
    st3.insert(5, "_abc_");
    cout << st3 << endl;
}

void testString8()
{
    real::string st = "Hello World";
    st.erase(st.size()-1);
    cout << st << endl;

    st = "Hello World";
    st.erase(0, 2);
    cout << st << endl;

    st = "Hello World";
    st.erase(0);
    cout << st << endl;

    st = "Hello World";
    st.erase(1, 5);
    cout << st << endl;
}

void testString9()
{
    real::string st1 = "Hello World";
    real::string st2 ;
    
    st2 = st1;
    cout << st2 << endl;

    real::string st3(st2);
    cout << st3 << endl;
}

int main()
{
    // testString();
    // testString2();
    // testString3();
    // testString4();
    // testString5();
    // testString6();
    // testString7();
    // testString8();
    testString9();
    return 0;
}